using UnityEditor;
using UnityEngine;

namespace LS.UnityExtensions.Editor
{
    public class LSGUIUtility
    {
        public static Color kSplitLineSkinnedColor
        {
            get
            {
                return EditorGUIUtility.isProSkin
                    ? new Color(0.6f, 0.6f, 0.6f, 1.333f)
                    : new Color(0.12f, 0.12f, 0.12f, 1.333f);
            }
        }
        
        public static Rect DoBorder(Rect rect)
        {
            float borderWidth = 1;
            DrawOutline(rect, borderWidth, LSGUIUtility.kSplitLineSkinnedColor);
            return new Rect(rect.x + borderWidth, rect.y + borderWidth, rect.width - 2f * borderWidth, rect.height - 2f * borderWidth);
        }
        
        public static void DrawOutline(Rect rect, float size, Color color)
        {
            if (UnityEngine.Event.current.type != UnityEngine.EventType.Repaint)
                return;
            Color color1 = GUI.color;
            GUI.color *= color;
            GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, size), (Texture) EditorGUIUtility.whiteTexture);
            GUI.DrawTexture(new Rect(rect.x, rect.yMax - size, rect.width, size), (Texture) EditorGUIUtility.whiteTexture);
            GUI.DrawTexture(new Rect(rect.x, rect.y + 1f, size, rect.height - 2f * size), (Texture) EditorGUIUtility.whiteTexture);
            GUI.DrawTexture(new Rect(rect.xMax - size, rect.y + 1f, size, rect.height - 2f * size), (Texture) EditorGUIUtility.whiteTexture);
            GUI.color = color1;
        }
    }
}
